package com.example.blog.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @Classname PageResult
 * @Description TODO
 * @Version 1.0.0
 * @Date 2023/3/1 20:42
 * @Created by wlh12
 */
public class PageResult<T> extends Result<PageResult.PageList<T>> {
    public PageResult() {
    }

    public static <T> PageResult<T> format(Page<T> page) {
        //只需要分页对象中的数据，页码，总条数
        List<T> dataList = page.getRecords();
        //当前页索引
        long pageCurrent = page.getCurrent();
        //总条数
        long total = page.getTotal();
        //当前一页显示条数
        long pageSize=page.getSize();
        PageList<T> pageList = new PageList();
        pageList.setPageCurrent((int) pageCurrent);
        pageList.setTotalCount((int) total);
        pageList.setList(dataList);
        pageList.setPageSize((int) pageSize);
        PageResult<T> result = new PageResult();
        result.setData(pageList);
        return result;
    }



    @Data
    public static class PageList<E> implements Serializable {

        protected Integer pageCurrent;

        protected Integer totalCount;

        protected Integer pageSize;

        protected List<E> list;

    }
}

